/**
 *
 */
package com.zhuoyue.elmt.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhuoyue.elmt.service.CsDtcsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.eit.eitsite.common.config.Global;
import com.eit.eitsite.common.persistence.Page;
import com.eit.eitsite.common.web.BaseController;
import com.eit.eitsite.common.utils.StringUtils;
import com.zhuoyue.elmt.entity.GgSbjc;
import com.zhuoyue.elmt.service.GgSbjcService;

/**
 * 设备信息Controller
 * @version 2016-12-18
 */
@Controller
@RequestMapping(value = "${adminPath}/elmt/ggSbjc")
public class GgSbjcController extends BaseController {

	@Autowired
	private GgSbjcService ggSbjcService;

	@Autowired
	private CsDtcsService csDtcsService;
	
	@ModelAttribute
	public GgSbjc get(@RequestParam(required=false) String id) {
		GgSbjc entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = ggSbjcService.get(id);
		}
		if (entity == null){
			entity = new GgSbjc();
		}
		return entity;
	}
	
	@RequiresPermissions("elmt:ggSbjc:view")
	@RequestMapping(value = {"list", ""})
	public String list(GgSbjc ggSbjc, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GgSbjc> page = ggSbjcService.findPage(new Page<GgSbjc>(request, response), ggSbjc); 
		model.addAttribute("page", page);
		return "zhuoyue/elmt/ggSbjcList";
	}

	@RequiresPermissions("elmt:ggSbjc:view")
	@RequestMapping(value = "form")
	public String form(GgSbjc ggSbjc, Model model) {
		model.addAttribute("ggSbjc", ggSbjc);
		return "zhuoyue/elmt/ggSbjcForm";
	}

	@RequiresPermissions("elmt:ggSbjc:edit")
	@RequestMapping(value = "save")
	public String save(GgSbjc ggSbjc, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, ggSbjc)){
			return form(ggSbjc, model);
		}
		ggSbjcService.save(ggSbjc);
		addMessage(redirectAttributes, "保存设备信息成功");
		return "redirect:"+Global.getAdminPath()+"/elmt/ggSbjc/?repage";
	}
	
	@RequiresPermissions("elmt:ggSbjc:edit")
	@RequestMapping(value = "delete")
	public String delete(GgSbjc ggSbjc, RedirectAttributes redirectAttributes) {
		ggSbjcService.delete(ggSbjc);
		addMessage(redirectAttributes, "删除设备信息成功");
		return "redirect:"+Global.getAdminPath()+"/elmt/ggSbjc/?repage";
	}

}